package ystp.service;


import org.springframework.stereotype.Service;
import ystp.dao.XinyaoshenqingMapper;
import ystp.model.Xinyaoshenqing;
import ystp.model.XinyaoshenqingExample;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Service
public class XinyaoshenqingService {

    @Resource
    XinyaoshenqingMapper ddMapper;

    public boolean add (Xinyaoshenqing ddXinyaoshenqing){
        return ddMapper.insert(ddXinyaoshenqing)==1;
    }

    public List<Map<String, Object>> findXinyaoPagingByXiangmuId(String ppxiangmuId,int ppPageIndex, int ppPageSize){
        int mmStartIndex = (ppPageIndex - 1) * ppPageSize;
        return ddMapper.findXinyaoPagingByXiangmuId(ppxiangmuId,mmStartIndex,ppPageSize);
    }

    public Integer getXinyaoCount(String ppXiangmuId) {
        Object mmCount = ddMapper.countXinyaoByXiangmuId(ppXiangmuId);
        return mmCount == null ? 0 : Integer.parseInt(mmCount.toString());
    }

    public List<Map<String, Object>> findXinyaoBiaojueByXiangmuId(String ppxiangmuId,String ppUserId,int ppPageIndex, int ppPageSize){
        int mmStartIndex = (ppPageIndex - 1) * ppPageSize;
        return ddMapper.findXinyaoBiaojueByXiangmuId(ppxiangmuId,ppUserId,mmStartIndex,ppPageSize);
    }

    public Integer countXinyaoBiaojueByXiangmuId(String ppXiangmuId,String ppUserId) {
        Object mmCount = ddMapper.countXinyaoBiaojueByXiangmuId(ppXiangmuId,ppUserId);
        return mmCount == null ? 0 : Integer.parseInt(mmCount.toString());
    }

    public boolean isExistByXiangmuId(String ppXiangmuId){
        XinyaoshenqingExample mmExample = new XinyaoshenqingExample();
        mmExample.createCriteria().andXiangmuidEqualTo(ppXiangmuId);
        return ddMapper.selectByExample(mmExample).size()>0;
    }

    public boolean deleteByXiangmuId(String ppXiangmuId){
        XinyaoshenqingExample mmExample = new XinyaoshenqingExample();
        mmExample.createCriteria().andXiangmuidEqualTo(ppXiangmuId);
        return ddMapper.deleteByExample(mmExample)>=0;
    }

    public Xinyaoshenqing findOne(String id){
        return ddMapper.selectByPrimaryKey(id);
    }

}
